import tuiData from '../data/tuijian/tuidata'
let oldData = JSON.parse(JSON.stringify(tuiData))
const tuijian ={
    //命名空间 作用就是划分清楚是谁的getters，mutations
    namespaced:true,
    state:{
        tuiData:tuiData,
        oldData:oldData,
        id:0,
    },
    getters:{
        sortTuiData(state){
            if(state.id==0){
                return oldData
            }else if(state.id==1){
                state.tuiData.sort((a,b)=>{
                    return a.item_info.category.ctime-b.item_info.category.ctime
                })
                return state.tuiData
            }else{
                state.tuiData.sort((a,b)=>{
                    return b.item_info.article_info.digg_count-a.item_info.article_info.digg_count
                })
                return state.tuiData
            }
        }
    },
    mutations:{
        changeId(state,payload){
            let {key} = payload
            state.id=key
            console.log(state.id)
        },
        addDigg(state,payload){
            let {key,sId} = payload
            if(sId==0){
                if(oldData[key].num){
                    oldData[key].num=0
                    oldData[key].item_info.article_info.digg_count-=1
                }else{
                    oldData[key].num=1
                    oldData[key].item_info.article_info.digg_count+=1
                }
                
            }else{
                
                console.log(state.tuiData[key].num)
                if(state.tuiData[key].num){
                    state.tuiData[key].num=0
                    state.tuiData[key].item_info.article_info.digg_count-=1
                }else{
                    state.tuiData[key].num=1
                    state.tuiData[key].item_info.article_info.digg_count+=1
                }
                
                
            }
            
        }
    },
    modules:{
        
    }
}
export default tuijian